Don't discard docopt error information
authorAlex Crichton <alex@alexcrichton.com>
Mon, 16 Feb 2015 04:45:59 +0000 (20:45 -0800)
committerAlex Crichton <alex@alexcrichton.com>
Tue, 17 Feb 2015 04:19:26 +0000 (20:19 -0800)
Not sure why we were doing this, it's quite useful!

Closes #1297

src/cargo/lib.rs
tests/test_cargo_new.rs

index d5737efd955ba1758e337c50509038ad5c6ffbb9..249ded37c9627ddf2fdbd7413d73e80291a4ef71 100644 (file)
@@ -210,12 +210,7 @@ fn flags_from_args<'a, T>(usage: &str, args: &[String],
                                    .version(Some(version()));
     docopt.decode().map_err(|e| {
         let code = if e.fatal() {1} else {0};
-        let desc = match e {
-            docopt::Error::WithProgramUsage(_, s) => s,
-            ref e if e.fatal() => e.description().to_string(),
-            e => e.to_string(),
-        };
-        CliError::from_error(human(desc), code)
+        CliError::from_error(human(e.to_string()), code)
     })
 }
 
index 0b268916af61da79bde7ba0f1bd8dfa310c28ffd..760c5d89fddb25a7c0d60cc3f1d3fc3557210644 100644 (file)
@@ -72,6 +72,8 @@ test!(no_argument {
     assert_that(cargo_process("new"),
                 execs().with_status(1)
                        .with_stderr("\
+Invalid arguments.
+
 Usage:
     cargo new [options] <path>
     cargo new -h | --help
@@ -189,3 +191,15 @@ test!(subpackage_no_git {
     assert_that(&paths::root().join("foo/components/subcomponent/.gitignore"),
                  is_not(existing_file()));
 });
+
+test!(unknown_flags {
+    assert_that(cargo_process("new").arg("foo").arg("--flag"),
+                execs().with_status(1)
+                       .with_stderr("\
+Unknown flag: '--flag'
+
+Usage:
+    cargo new [..]
+    cargo new [..]
+"));
+});